package com.lottery.material.interceptor;

import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Description：自定义拦截器
 * Created by 朱正磊 on 2019-03-25 14:08
 */
@Component
public class CommonInterceptor implements HandlerInterceptor {

    //开始放行
    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response,
                             Object handler) throws Exception {
        return true;
    }

    //中间过程
    @Override
    public void postHandle(HttpServletRequest request,
                           HttpServletResponse response, Object handler,
                           @Nullable ModelAndView modelAndView) throws Exception {
        //获取根路径
        request.setAttribute("ctx", request.getContextPath());
    }

    //结尾不作处理
    @Override
    public void afterCompletion(HttpServletRequest request,
                                HttpServletResponse response,
                                Object handler, @Nullable Exception ex) throws Exception {

    }

}
